#

| Chapter 9 Saving Time on the Command Line |

## 9.15 Throwaway Scripts for Complicated Commands

[If your shell has interactive command-line editing, like the Korn shell (11.13) does, the technique here can still be useful. As Mike says, you might want to save the script and use it later. -JP]

Shell scripts are often handy, even if you never intend to write software. One problem that most users face is typing a complicated command correctly. For example, let's say you need to type the following monstrosity:

>     % soelim a.ms b.ms | pic | eqn | tbl | troff -ms -a | more

(This isn't unrealistic; I've typed this particular command a few times.) Rather than spend all that time typing, then backspacing to fix some error, then typing some more, then backspacing again, you can create a very simple "throwaway" shell script with your favorite editor:

>     # shell script "foo" for one-time use
>     soelim a.ms b.ms | pic | eqn | tbl | troff -ms -a -rz1 | more

Use your editor to play with the script until the command looks right - any half-competent text editor will be much easier to work with than the "raw" command line. Then execute it like this:

>     % sh foo

If you don't think you'll need this command again, you can delete the file - or use a temporary file (21.3) in the first place. But before you use rm, think: most things that you do once, you'll need to do again. Give it an intelligent name, and save it in your bin directory (4.2). You're now a shell programmer.

This is also a great idea for complex sequences of commands.

- ML

9.14 Using Here Documents for Form Letters, etc. |  | 9.16 Command Substitution